Skip to content

Conversation

etienne-lms
Copy link
Contributor

Correct eeprom_stm32_write() to return a valid errno instead of mixing HAL return values and errno return values.

Clarify HAL return value is of type HAL_StatusTypeDef and not an int in eeprom_stm32_read().

Comment on lines 73 to 75
if (HAL_FLASHEx_DATAEEPROM_Unlock() != HAL_OK) {
return -EIO;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: there should be consistency about whether driver uses

if (xxx() != HAL_OK) {
   ...fail
}

or

ret = xxx();
if (ret != HAL_OK) {
   ...fail
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think when the return value is needed only to be tested straight, it's not really needed to be stored then tested, as here. Is this function, below, the return value is used not only with an if() instruction.
That said, I'm fine using the latter way (among the 2 you mentioned above).

if (ret != HAL_OK) {
LOG_ERR("failed to write to EEPROM (err %d)", ret);
HAL_FLASHEx_DATAEEPROM_Lock();
k_mutex_unlock(&lock);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seomthing's wrong in the 1st commit. EEPROM should be locked back. I'll fix.

Comment on lines 73 to 75
if (HAL_FLASHEx_DATAEEPROM_Unlock() != HAL_OK) {
return -EIO;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think when the return value is needed only to be tested straight, it's not really needed to be stored then tested, as here. Is this function, below, the return value is used not only with an if() instruction.
That said, I'm fine using the latter way (among the 2 you mentioned above).

Comment on lines 83 to 86
ret = HAL_FLASHEx_DATAEEPROM_Lock();
if (ret != HAL_OK) {
LOG_ERR("failed to lock to EEPROM (err %d)", ret);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HAL_FLASHEx_DATAEEPROM_Lock only implemented on L0/L1 and does not perform error checking.
I'm fine to perform the error checking, but LOG_ERR with value report seems overkill.

Correct eeprom_stm32_write() to return a valid errno instead
of mixing HAL return values and errno return values.

Clarify HAL return value is of type HAL_StatusTypeDef and not an
int in eeprom_stm32_read().

Remove printing of HAL_FLASHEx_DATAEEPROM_Lock() error code since
not very useful.

Signed-off-by: Etienne Carriere <[email protected]>
Add missing test of HAL_FLASHEx_DATAEEPROM_Unlock() return value.

By the way, add a error trace message when failing to relock the
EEPROM after we failed to program it.

Signed-off-by: Etienne Carriere <[email protected]>
@etienne-lms
Copy link
Contributor Author

Review comment addressed.
I also fixed an unbalanced mutex locking issue I introduced in my original series.

HAL_FLASHEx_DATAEEPROM_Unlock();
hal_ret = HAL_FLASHEx_DATAEEPROM_Unlock();
if (hal_ret != HAL_OK) {
LOG_ERR("failed to unlock to EEPROM");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOG_ERR still feels overkill but ok

Copy link

@etienne-lms etienne-lms added this to the v4.3.0 milestone Oct 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants